package lion.web.taglib.i18n;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import lion.dev.i18n.StringManager;
import lion.dev.lang.Lang;

/**
 * @author lion
 * @email hl_0074@sina.com
 * @date 2014年6月24日
 */
public class I18NTag extends SimpleTagSupport {

	private String key;
	private String base;

	private PageContext pc;
	private Locale locale;

	public I18NTag() {

	}

	@Override
	public void doTag() throws JspException, IOException {

		pc = (PageContext) this.getJspContext();
		locale = Lang.nvl((Locale) pc.getSession().getAttribute("lion.i18n.local"), pc.getRequest().getLocale());
		StringManager sm = StringManager.getManager(this.base, locale);

		this.getJspContext().getOut().write(sm.getString(key));
	}

	public void setKey(String key) {

		this.key = key;
	}

	public void setBase(String base) {

		this.base = base;
	}

}
